<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib  uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
		<link href="css/table.css" rel="stylesheet" type="text/css" />
		<link href="css/background.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/table.js"></script>
		<script type="text/javascript" src="js/openwindow.js"></script>
		<script type="text/javascript">
	function page(currentPage){
		$("#pageId").val(currentPage);
		document.pageForm.submit();
	}
function clearInfo(){
	$("#account").val("");
	$("#name").val("");
	$("#roleId").val("");
	$("#orgName").val("");
	$("#volume").val("");
	document.searchForm.submit();
}	

function initadd(){
	var url="init_add.action";
	openWindow(url,850,430);
}	

function deleteUser(){
	var arry="";
	var count=0;
	var checks=$("input[name='ids']");
	for(var i=0;i<checks.length;i++){
		if(checks[i].checked){
			if(arry==''){
			arry+="ids="+checks[i].value;
			}else{
			arry+="&ids="+checks[i].value;
			}
			count++;
		}
	}
	if(count==0){
		alert("请选择要删除的数据！");
		return;
	}
	if(confirm("确定要删除？")){
		$.post("deleteUser.action",arry,function(data){
			if(data=="success"){
				alert("删除数据成功！");
				var currentPage=$("#currentPage").val();
				page(currentPage);
			}else{
				alert("删除数据失败！");
			}
		});
	}
}

function userYesNo(id,val){
	var str="";
	if(val=='0'){
		str="确定要启用此用户？";
	}else{
		str="确定要禁用此用户？";
	}
     if(confirm(str)){
	var param={"userId":id,"status":val};
	$.post("userYesNo.action",param,function(data){
				alert(data);
				var currentPage=$("#currentPage").val();
				page(currentPage);
	});
	}
}

function updateUser(id){
var currentPage=$("#currentPage").val();
 var url="getUserInfo.action?userId="+id+"&currentPage="+currentPage;
 openWindow(url,750,430);
}

function updatePsw(id){
	var url="getUserPsw.action?userId="+id;
	openWindow(url,650,200)
}
function accountSort(currentPage){
	var accountSort=$("#accountSort").val();
	var orgSort=$("#orgSort").val();
	accountSort=parseInt(accountSort)+1;
	orgSort=0;
	$("#accountSort").val(accountSort);
	$("#orgSort").val(orgSort);
	$("#pageId").val(currentPage);
	document.pageForm.submit();
}
function orgSort(currentPage){
	var accountSort=$("#accountSort").val();
	var orgSort=$("#orgSort").val();
	accountSort=0;
	orgSort=parseInt(orgSort)+1;
	$("#accountSort").val(accountSort);
	$("#orgSort").val(orgSort);
	$("#pageId").val(currentPage);
	document.pageForm.submit();
}
$(function(){
	var accountSort=$("#accountSort").val();
	var orgSort=$("#orgSort").val();
	if(accountSort!=0){
		if(accountSort%2==1){
			$("#sort1").attr("src","image/arrows/arrows1.jpg");
		}
		else{
			$("#sort1").attr("src","image/arrows/arrows2.jpg");
		}
	}
	else{
		$("#sort1").remove();
	}
	if(orgSort!=0){
		if(orgSort%2==1){
			$("#sort2").attr("src","image/arrows/arrows1.jpg");
		}
		else{
			$("#sort2").attr("src","image/arrows/arrows2.jpg");
		}
	}
	else{
		$("#sort2").remove();
	}
});

	function valiadeVolume(ths){
		var reg=/^[1-9]\d*$/;
		if(!reg.test(ths.value)){
			ths.value=100;
		}
	}
</script>
	</head>
	<body>
		<div class="topdiv">
			<form action="userManager.action" method="post" name="searchForm">
				<div>
					帐户：<input type="text"  id="account" name="account" value="${account}" style="width: 100px;"/>
					&nbsp; 姓名：<input type="text"  id="name" name="name" value="${name}" style="width: 100px;"/>
					&nbsp; 邮箱容量：
					<input type="text"  onfocus="valiadeVolume(this)" onkeyup="valiadeVolume(this)" id="volume" name="volume"
						value="${volume}" style="width: 60px;"/>
					&nbsp;部门：
					<input type="text"  id="orgName" name="orgName"
						value="${orgName}" style="width: 120px;"/>
					&nbsp;所属角色：
					<s:select id="roleId" list="roleList" headerKey="" headerValue="--请选择--" listKey="id" listValue="name" name="roleId" value="roleId" theme="simple"></s:select>
				</div>
				<table align="right">
				 <tr>
					<td>
						<input class="button_04" type="submit" value="立即查找" />
				 		<input align="right"  class="button_02" type="button" onclick="clearInfo()" value="清除" />
					</td>
				 </tr>
				</table>
			</form>
		</div>
		<table  border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
					<td style="background: url('image/wsoa_window_002.gif');">
						<table border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td align="center"
										style="background: url('image/wsoa_window_002.gif');"
										width="10">
										<img src="image/center_19.gif">
									</td>
									<td align="center"
										style="background: url('image/wsoa_window_002.gif');"></td>
									<td>
										系统管理 &gt; 基础设置 &gt; 用户管理
									</td>
								</tr>
						</table>
					</td>
					<td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
				</tr>
				<tr>
					<td style="background: url('image/wsoa_window_010.gif');" width="1">&nbsp;</td>
					<td>
						<table class="intable">
							<tr>
								<td>
									<input type="button" onclick="initadd()" value="添加"
										class="button_02" />
								</td>
								<td>
									<input type="button" onclick="deleteUser()" value="删除"
										class="button_02" />
								</td>
							</tr>
						</table>
						<table id="tabllist" class="righ_list" frame="box" cellspacing="1" cellpadding="0" width="100%" border="0">
							<tr class="reigh_list2">
								<th align="left" class="bg_tr" width="5%">
									<input type="checkbox" onclick="checkAll()" id="all">
								</th>
								<th align="left" width="8%"
									onclick="accountSort(${currentPage })" style="cursor: hand">
									账户
									<img id="sort1" height="10px" width="15px">
								</th>
								<th align="left">
									姓名
								</th>
								<th align="left" width="10%">
									手机
								</th>
								<th align="left" width="30%" onclick="orgSort(${currentPage })"
									style="cursor: hand">
									部门
									<img id="sort2" height="10px" width="15px">
								</th>
								<th align="left" width="10%">
									职位
								</th>
								<th align="left" width="5%">
									排序
								</th>
								<th align="left" width="5%">
									状态
								</th>
								<th align="left" width="15%">
									操作
								</th>
							</tr>
							<c:if test="${empty userList}">
								<tr id="row">
									<td colspan="9">
										没有相关记录！
									</td>
								</tr>
							</c:if>
							<c:forEach items="${userList}" var="user">
								<tr id="row" onmouseover="overStyle(this)"
									onmouseout="outStyle(this)">
									<td align="center">
										<input type="checkbox" name="ids" value="${user.id}">
									</td>
									<td>
										${user.account}
									</td>
									<td>
										${user.name}
									</td>
									<td>
										${user.phone}
									</td>
									<td>
										${user.orgName}
									</td>
									<td>
										${user.position}
									</td>
									<td>
										${user.px}
									</td>
									<td>
										${user.status=='0'?"有效":"无效"}
									</td>
									<td align="center">
										<img alt="修改" onclick="updateUser('${user.id}')"
											src="image/operate_update.gif" style="cursor: pointer">
										&nbsp;
										<img alt="密码修改" onclick="updatePsw('${user.id}')"
											src="image/operate_psw.gif" style="cursor: pointer">
										&nbsp;
										<c:if test="${user.status=='1'}">
											<img alt="启用" onclick="userYesNo('${user.id}','0')"
												src="image/select.gif" style="cursor: pointer">
										</c:if>
										<c:if test="${user.status=='0'}">
											<img alt="禁用" onclick="userYesNo('${user.id}','1')"
												width="15" height="15" src="image/modifypass.gif"
												style="cursor: pointer">
										</c:if>
									</td>
								</tr>
							</c:forEach>
						</table>
					</td>
					<td style="background: url('image/wsoa_window_006.gif');" width="1">
						&nbsp;
					</td>
				</tr>
				<tr>
					<td height="1" width="1">
						<img src="image/wsoa_window_009.gif" height="16" width="14">
					</td>
					<td style="background: url('image/wsoa_window_008.gif');"
						height="1"></td>
					<td height="1" width="1">
						<img src="image/wsoa_window_007.gif" height="16" width="12">
					</td>
				</tr>
		</table>
		<div class="pageDiv">
			<form action="userManager.action" method="post" name="pageForm">
				<input type="hidden" name="account" value="${account}">
				<input type="hidden" name="name" value="${name}">
				<input type="hidden" name="orgName" value="${orgName}">
				<input type="hidden" name="roleId" value="${roleId}">
				<input type="hidden" name="volume" value="${volume}">
				<input type="hidden" id="pageId" name="currentPage">
				<input type="hidden" id="accountSort" name="accountSort" value="${accountSort }">
				<input type="hidden" id="orgSort" name="orgSort" value="${orgSort }">
				<%@include file="../page/page.jsp"%>
			</form>
			</div>
	</body>
</html>